<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title></title>
	</head>
	<body>
		<script>
			// 简单排序
			let arr = [49, 38, 65, 97, 76, 13, 27, 49];

			function sort(arr, n) {
				for (let i = 0; i < n - 1; i++) {
					// debugger
					let m = i;
					// 注意，这里是j < n,不是j < n - 1，不然最后一次遍历不行
					for (let j = i + 1; j < n; j++) {
						if (arr[j] < arr[m]) {
							m = j;
						}
					}
					if (m != i) {
						[arr[m], arr[i]] = [arr[i], arr[m]];
					}
				}
				return arr;
			}
			console.log(sort(arr, arr.length));
		</script>
	</body>
</html>
